package org.csu.storemanage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.csu.storemanage.mapper.CartMapper;
import org.csu.storemanage.mapper.OrderMapper;
import org.csu.storemanage.pojo.CartItem;
import org.csu.storemanage.pojo.Order;
//import org.mockito.internal.matchers.Or;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
@MapperScan("org.csu.storemanage.mapper")
public class OrderService {
    //地址管理服务
    private OrderMapper orderMapper;
    private CartMapper cartMapper;

    @Autowired
    public OrderService(OrderMapper orderMapper,CartMapper cartMapper)//构造注入
    {
        this.orderMapper = orderMapper;
        this.cartMapper = cartMapper;
    }

    public List< Order > getAllOrder(){
        QueryWrapper wrapper = new QueryWrapper<>();
        List<Order> orderList = orderMapper.selectList(wrapper);
        return orderList;
    }

    public void deleteOrderByOrderId(int orderId){
        QueryWrapper<CartItem> cartWrapper = new QueryWrapper<>();
        cartWrapper.eq("orderBelong",orderId);
        cartMapper.delete(cartWrapper);

        QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.eq("orderId",orderId);
        orderMapper.delete(orderQueryWrapper);
    }


    public void changeStatement(int orderBelong,int statement){
        UpdateWrapper<Order> wrapper = new UpdateWrapper<>();
        wrapper.eq("orderId",orderBelong);
        wrapper.set("statement",statement);
        orderMapper.update(null,wrapper);
    }

    public void editOrder(int orderId,String name,String number,String detail){
        UpdateWrapper<Order> wrapper = new UpdateWrapper<>();
        wrapper.eq("orderId",orderId);
        wrapper.set("name",name);
        wrapper.set("number",number);
        wrapper.set("detail",detail);
        orderMapper.update(null,wrapper);
    }



}
